package com.spc.car.web.controller.std;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.spc.car.common.utils.StringUtils;
import com.spc.car.core.framework.web.domain.AjaxResult;
import com.spc.car.data.entity.std.StdGbIndustrialClassification;
import com.spc.car.data.service.std.StdGbIndustrialClassificationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@Api(tags = "行业分类")
@Slf4j
@Validated
@RestController
@RequestMapping("/stdGbClass")
public class StdGbIndustrialClassificationController {

    @Autowired
    StdGbIndustrialClassificationService stdGbIndustrialClassificationService;

    @ApiOperation(value = "行业分类列表", notes = "查询行业分类列表，通过parentCode获取子级分类列表")
    @PostMapping("/listStdGbClassification")
    public AjaxResult listStdGbClassification(@RequestParam(name = "name", required = false) String name,
                                              @RequestParam(name = "parentCode", required = false) String parentCode) {
        List<StdGbIndustrialClassification> classificationList =
                stdGbIndustrialClassificationService.list(new LambdaQueryWrapper<StdGbIndustrialClassification>()
                        .like(StringUtils.isNotBlank(name), StdGbIndustrialClassification::getName, name)
                        .eq(StdGbIndustrialClassification::getStatus, "A")
                        .eq(StringUtils.isNotBlank(parentCode), StdGbIndustrialClassification::getParentCode, parentCode)
                        .isNull(StringUtils.isBlank(parentCode), StdGbIndustrialClassification::getParentCode)
                        .orderByAsc(StdGbIndustrialClassification::getCode));

        return AjaxResult.success("查询成功！", classificationList);
    }
}
